﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using M7;

namespace C7
{
	/// <summary>
	/// Interaction logic for InternetModule.xaml
	/// </summary>
    public partial class InternetModule : UserControl
    {
        private WindowOperations WindowOPs = new WindowOperations();
        public InternetModule()
        {
            this.InitializeComponent();
            WindowOPs.TextBoxesToHandlers(LayoutRoot);
            WindowOPs.WindowToAnimationHandlers(LayoutRoot, true);
        }

        private void GoButtonClick(object sender, RoutedEventArgs e)
        {
            wbBrowser.Visibility = Visibility.Visible;

            Uri uri = new Uri("http://www." + this.tbAddressBar.Text, UriKind.RelativeOrAbsolute);
            if (!uri.IsAbsoluteUri)
            {
                //MessageBox.Show("The Address URI must be absolute eg 'http://www.microsoft.com'");
                return;
            }
            this.wbBrowser.Navigate(uri);
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumInternet.Website;
            SendMsg.obj = tbAddressBar.Text;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }

        private void imgBack_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (wbBrowser.CanGoBack)
            {
                wbBrowser.GoBack(); 
            }
        }

        private void imgForward_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (wbBrowser.CanGoForward)
            {
                wbBrowser.GoForward(); 
            }
        }

        private void tbAddressBar_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                GoButtonClick(sender, e);
        }
    }
}